# 中文变量C++博客后端服务 Makefile

CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2
INCLUDES = -I./include
LIBS = -lpthread

# 源文件
SRCS = main.cpp
OBJS = $(SRCS:.cpp=.o)
TARGET = 中文博客后端

# 默认目标
all: $(TARGET)

# 链接可执行文件
$(TARGET): $(OBJS)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)

# 编译源文件
%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

# 下载依赖
download-deps:
	@echo "正在下载依赖库..."
	@mkdir -p include
	@if [ ! -f "include/httplib.h" ]; then \
		echo "下载 httplib.h..."; \
		curl -L -o include/httplib.h https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h; \
	fi
	@if [ ! -f "include/json.hpp" ]; then \
		echo "下载 json.hpp..."; \
		curl -L -o include/json.hpp https://raw.githubusercontent.com/nlohmann/json/develop/single_include/nlohmann/json.hpp; \
	fi
	@echo "依赖下载完成"

# 清理
clean:
	rm -f $(OBJS) $(TARGET)

# 运行
run: $(TARGET)
	./$(TARGET)

# 帮助
help:
	@echo "中文变量C++博客后端服务"
	@echo "可用命令:"
	@echo "  make download-deps - 下载依赖库"
	@echo "  make              - 编译项目"
	@echo "  make run          - 编译并运行"
	@echo "  make clean        - 清理编译文件"
	@echo "  make help         - 显示帮助"

.PHONY: all clean run help download-deps
